﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Entidades.Karaoke;

namespace Datos.Karaoke
{
    public class KarSolicitudActualizacionCancionDAL
    {
        public static string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();

        public static int AgregarSolicitudActualizacionCancion(KarSolicitudActualizacionCancion obj)
        {
           
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("[dbo].[sp_Kar_InsertarSolActCancion]", con);

            com.Parameters.AddWithValue("@idTipoActualizacion", obj.IdTipoActualizacion);
            com.Parameters.AddWithValue("@idMotivo", obj.IdMotivo);
            com.Parameters.AddWithValue("@observacion", obj.Observacion);
            com.Parameters.AddWithValue("@codUsuario", obj.CodUsuario);

            SqlParameter p = new SqlParameter();
            p.Direction = System.Data.ParameterDirection.Output;
            p.Value = 0;
            p.ParameterName = "@Identity";

            com.Parameters.Add(p);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                com.Transaction = con.BeginTransaction();
                int result = com.ExecuteNonQuery();
                if (result > 0)
                {
                    result = Convert.ToInt32(com.Parameters["@Identity"].Value);
                    com.Transaction.Commit();
                }
                else
                {
                    com.Transaction.Rollback();
                }

                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();

            }

        }

     
    }
}
